Skip to content

feat: add prompt variable compilation#28

Merged
Steffen911 merged 2 commits intolangfuse:mainfrom
ChoMinGi:feat/prompt-compilation
Apr 23, 2026
Merged

feat: add prompt variable compilation#28
Steffen911 merged 2 commits intolangfuse:mainfrom
ChoMinGi:feat/prompt-compilation

Conversation

@ChoMinGi
Copy link
Copy Markdown
Contributor

@ChoMinGi ChoMinGi commented Mar 23, 2026

Summary

Adds PromptTemplate and PromptCompiler under com.langfuse.client.prompt — no changes to Fern-generated code.

PromptTemplate handles {{var}} replacement and variable extraction. PromptCompiler wraps it for TextPrompt and ChatPrompt types so the usage feels similar to the Python/JS SDKs.
Tests cover basic replacement, missing/extra vars, null handling, edge cases for both text and chat prompts.

Closes #13

Scope

  • Text prompt compilation
  • Chat prompt compilation (per-message variable substitution)
  • PlaceholderMessage expansion (inserting message lists at placeholder positions) — not included in this PR, planned as a follow-up

Test plan

  • 20 unit tests for PromptTemplate (basic replacement, missing/extra vars, null handling, whitespace, edge cases)
  • 5 unit tests for PromptCompiler (text prompt, chat prompt, placeholder skipping, empty prompt)

Add PromptTemplate and PromptCompiler utilities for {{variable}}
template compilation, matching the Python/JS SDK compile() behavior.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 23, 2026

CLA assistant check
All committers have signed the CLA.

@ChoMinGi ChoMinGi marked this pull request as ready for review March 24, 2026 02:33
@Steffen911
Copy link
Copy Markdown
Member

@ChoMinGi Thank you a lot! Did you test whether a regeneration of the client using fern from the langfuse/langfuse repo would overwrite the additions you've made here? If not, could you test it and confirm that this doesn't lead to issues?

@Steffen911 Steffen911 self-requested a review April 22, 2026 14:36
@Steffen911 Steffen911 self-assigned this Apr 22, 2026
@ChoMinGi
Copy link
Copy Markdown
Contributor Author

Hi @Steffen911, thanks for the review!

I confirmed that Fern regeneration does not affect the files added in this PR.
Changes are in com.langfuse.client.prompt, which is outside the Fern-generated paths (client/, client/core/, client/resources/) None of our files contain the auto-generated by Fern marker, so there's no overlap.
I also tested this locally by running the fernapi/fern-java-sdk:3.38.1 generator via Docker against the current IR — the prompt/ package was left untouched.

@Steffen911 Steffen911 merged commit 23ff4ca into langfuse:main Apr 23, 2026
4 checks passed
@ChoMinGi
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and merging this, @Steffen911!
Really appreciate you taking the time. Looking forward to contributing more to langfuse-java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle prompt variables

3 participants